/**
 * Copyright &copy; 2012-2016 <a href="https://www.kaaction.com">KAA</a> All rights reserved All rights reserved.
 */
package com.kaaction.modules.market.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.kaaction.common.config.Global;
import com.kaaction.common.persistence.Page;
import com.kaaction.common.web.BaseController;
import com.kaaction.common.utils.StringUtils;
import com.kaaction.modules.market.entity.EventLotteryDetail;
import com.kaaction.modules.market.service.EventLotteryDetailService;

/**
 * 获奖结果Controller
 * @author zengbiao
 * @version 2017-04-22
 */
@Controller
@RequestMapping(value = "${adminPath}/market/eventLotteryDetail")
public class EventLotteryDetailController extends BaseController {

	@Autowired
	private EventLotteryDetailService eventLotteryDetailService;
	
	@ModelAttribute
	public EventLotteryDetail get(@RequestParam(required=false) String id) {
		EventLotteryDetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = eventLotteryDetailService.get(id);
		}
		if (entity == null){
			entity = new EventLotteryDetail();
		}
		return entity;
	}
	
	@RequiresPermissions("market:eventLotteryDetail:view")
	@RequestMapping(value = {"list", ""})
	public String list(EventLotteryDetail eventLotteryDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EventLotteryDetail> page = eventLotteryDetailService.findPage(new Page<EventLotteryDetail>(request, response), eventLotteryDetail); 
		model.addAttribute("page", page);
		return "modules/market/eventLotteryDetailList";
	}

	@RequiresPermissions("market:eventLotteryDetail:view")
	@RequestMapping(value = "form")
	public String form(EventLotteryDetail eventLotteryDetail, Model model) {
		model.addAttribute("eventLotteryDetail", eventLotteryDetail);
		return "modules/market/eventLotteryDetailForm";
	}

	@RequiresPermissions("market:eventLotteryDetail:edit")
	@RequestMapping(value = "save")
	public String save(EventLotteryDetail eventLotteryDetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, eventLotteryDetail)){
			return form(eventLotteryDetail, model);
		}
		eventLotteryDetailService.save(eventLotteryDetail);
		addMessage(redirectAttributes, "保存获奖结果成功");
		return "redirect:"+Global.getAdminPath()+"/market/eventLotteryDetail/?repage";
	}
	
	@RequiresPermissions("market:eventLotteryDetail:edit")
	@RequestMapping(value = "delete")
	public String delete(EventLotteryDetail eventLotteryDetail, RedirectAttributes redirectAttributes) {
		eventLotteryDetailService.delete(eventLotteryDetail);
		addMessage(redirectAttributes, "删除获奖结果成功");
		return "redirect:"+Global.getAdminPath()+"/market/eventLotteryDetail/?repage";
	}

}